package com.study_online.controller;/*
    张昊（java文件）
 
*/

import com.study_online.domain.ResultInfo;
import com.study_online.service.CommentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;



@RestController
@RequestMapping("/comment")
public class CommentController {

    //根据视频的id查询该视频下的所有评论
    @Autowired
    private CommentService commentService;



    @RequestMapping("/findvideoId")
    public ResultInfo findById(Integer videoId){
        ResultInfo info = commentService.findById(videoId);
        return info;
    }

    //添加评论信息
    @Autowired
    HttpServletRequest request;
    @RequestMapping("/addComment")
    public ResultInfo addComment(Integer vidoId){
        String parameter = request.getParameter("text");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = new Date();
        String nowTime = format.format(date);
        ResultInfo info = commentService.addComment(vidoId, parameter, nowTime);
        return info;
    }

    //删除评论信息
    @RequestMapping("/deleteComment")
    public ResultInfo deleteComment(Integer commentId){
        ResultInfo info = commentService.deleteComment(commentId);
        return info;
    }


    //添加评论的回复
    @RequestMapping("/addCommentB")
    public ResultInfo addCommentB(Integer comment,String text){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = new Date();
        String nowTime = format.format(date);
        ResultInfo info = commentService.addCommentB(comment, text, nowTime);
        return info;
    }

    //删除根据id删除回复的内容
    @RequestMapping("/deleteCommentB")
    public ResultInfo deleteCommentB(Integer commentBId){
        ResultInfo info = commentService.deleteCommentB(commentBId);
        return info;
    }







}
